﻿Public Class FAManagement
    Implements SuperForm

    Private _FATypeIni As Integer '' Quản lý loại tài sản cố định nào
    Private _ModuleOwner As Dictionary(Of Integer, String)
    Private _FATypeOwner As List(Of Integer)

    Private cm As CurrencyManager
    Private faDA As DataTable
    Private detailDA As DataTable
    Private handoverDA As DataTable
    Private inventoryDA As DataTable
    Private repairDA As DataTable
    Private disposalDA As DataTable

    Private _curRowFASelected As Integer = -1

    Private _curRowDetailSelected As Integer = -1

    Private _curRowHandoverSelected As Integer = -1 '' Row được chọn

    Private _curRowInventorySelected As Integer = -1

    Private _curRowRepairSelected As Integer = -1

    Private _curRowDisposalSelected As Integer = -1


    Public Sub New(ByVal moduleOwner As Dictionary(Of Integer, String))

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me._ModuleOwner = moduleOwner
        Me._FATypeOwner = MyLibrary.getFATypeOwner(Me._ModuleOwner)
        Me._FATypeIni = Me._FATypeOwner.Item(0)

        '' Gắn giá trị cho các trường hiện thị đúng với từng loại tài sản
        ini()

    End Sub

    Public Function ini() As Boolean
        Select Case Me._FATypeIni

            Case CONSTANT.FIXED_ASSETS_TYPE._HOUSE
                Me.Text = "Quản Lý Nhà Cửa"
                Me.tcFA.TabPages(0).Text = "Danh Mục Nhà Cửa"
                Me.lblLogo.Text = "Quản Lý Nhà Cửa"

            Case CONSTANT.FIXED_ASSETS_TYPE._COMPUTER
                Me.Text = "Quản Lý Máy Tính"
                Me.tcFA.TabPages(0).Text = "Danh Mục Máy Tính"
                Me.lblLogo.Text = "Quản Lý Máy Tính"
            Case CONSTANT.FIXED_ASSETS_TYPE._PHOTO
                Me.Text = "Quản Lý Máy Photo"
                Me.tcFA.TabPages(0).Text = "Danh Mục Máy Photo"
                Me.lblLogo.Text = "Quản Lý Máy Photo"
            Case CONSTANT.FIXED_ASSETS_TYPE._PROJECTOR
                Me.Text = "Quản Lý Máy Chiếu"
                Me.tcFA.TabPages(0).Text = "Danh Mục Máy Chiếu"
                Me.lblLogo.Text = "Quản Lý Máy Chiếu"
            Case CONSTANT.FIXED_ASSETS_TYPE._PRINTER
                Me.Text = "Quản Lý Máy In"
                Me.tcFA.TabPages(0).Text = "Danh Mục Máy In"
                Me.lblLogo.Text = "Quản Lý Máy In"
            Case CONSTANT.FIXED_ASSETS_TYPE._OTO
                Me.Text = "Quản Lý Oto"
                Me.tcFA.TabPages(0).Text = "Danh Mục Oto"
                Me.lblLogo.Text = "Quản Lý Oto"
            Case CONSTANT.FIXED_ASSETS_TYPE._INSTRUMENT
                Me.Text = "Quản Lý Đồ Dùng - Dụng Cụ"
                Me.tcFA.TabPages(0).Text = "Danh Mục Dụng Cụ"
                Me.lblLogo.Text = "Quản Lý Đồ Dùng - Dụng Cụ"

        End Select
    End Function

    Private Sub FAManagement_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        role()
        loadAll()
    End Sub

    Public Function loadAll() As Boolean Implements SuperForm.loadAll
        loadFA()
        loadDetail()
        loadHandover()
        loadInventory()
        loadRepair()
        loadDisposal()

        '' Viet: Khởi tạo dòng đầu tiên được chọn
        If (Not Me.grvFA Is Nothing And Not faDA Is Nothing) Then
            Me._curRowFASelected = 0
            Me.grvFA.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
            Me.grvFA.Rows(0).Selected = True
            specifyCorrespondingDetail()
            specifyCorrespondingDisposal()
            specifyCorrespondingHandover()
            specifyCorrespondingInventory()
            specifyCorrespondingRepair()
        End If
        

        Return True
    End Function

    Private Function role() As Boolean
        '' Việt: Phân quyền
        Dim j As Integer = 0
        Dim rootNodeNameOwner As List(Of String) = New List(Of String)
        For j = 0 To Me._FATypeOwner.Count - 1
            Select Case Me._FATypeOwner.Item(j)
                Case CONSTANT.FIXED_ASSETS_TYPE._COMPUTER
                    rootNodeNameOwner.Add(ROOT_NODE_NAME._Root_Machine)
                Case CONSTANT.FIXED_ASSETS_TYPE._HOUSE
                    rootNodeNameOwner.Add(ROOT_NODE_NAME._Root_House)
                Case CONSTANT.FIXED_ASSETS_TYPE._INSTRUMENT
                    rootNodeNameOwner.Add(ROOT_NODE_NAME._Root_Instrument)
                Case CONSTANT.FIXED_ASSETS_TYPE._OTO
                    rootNodeNameOwner.Add(ROOT_NODE_NAME._Root_Transport)
                Case CONSTANT.FIXED_ASSETS_TYPE._PHOTO
                    rootNodeNameOwner.Add(ROOT_NODE_NAME._Root_Machine)
                Case CONSTANT.FIXED_ASSETS_TYPE._PRINTER
                    rootNodeNameOwner.Add(ROOT_NODE_NAME._Root_Machine)
                Case CONSTANT.FIXED_ASSETS_TYPE._PROJECTOR
                    rootNodeNameOwner.Add(ROOT_NODE_NAME._Root_Machine)
            End Select
        Next
        rootNodeNameOwner.Add(ROOT_NODE_NAME._Root_Council)

        Dim treeView As TreeView = Me.menuTreeView
        Dim i As Integer = 0
        Dim count As Integer = treeView.Nodes.Count
        While (count > 1 And i < count)
            If (rootNodeNameOwner.Contains(treeView.Nodes(i).Name)) Then
                i = i + 1
            Else
                treeView.Nodes(i).Remove()
                count = count - 1
            End If
        End While
    End Function

    Private Function loadFA() As Boolean Implements SuperForm.loadFA


        Me.grvFA.ClearSelection()

        Dim sqlWhere = "" & I_TSCD.ColumnName_FAType & " =" & Me._FATypeIni & ""
        Dim x_po As PO = New X_TSCD(-1)

        Me.faDA = New Query(x_po, sqlWhere).dataTable

        If (Me.faDA Is Nothing) Then
            Me.grvFA.DataSource = Me.faDA
            Return False
        End If


        cm = Me.BindingContext(faDA)
        Me.grvFA.DataSource = Me.faDA
        Me.grvFA.AutoGenerateColumns = True


        Dim i As Integer = 0

        For i = 0 To Me.grvFA.ColumnCount - 1
            Me.grvFA.Columns(i).HeaderText = x_po.getPoInfo.getPOInfoColumn(i).getColumnName.ToUpper
        Next
        Me.grvFA.Columns(0).Visible = False



    End Function

    '' Tùy biến = Thêm tham số tùy thuộc và FAType
    Private Function loadDetail() As Boolean Implements SuperForm.loadDetail
        Me.grvDetail.ClearSelection()
        Dim x_po As PO

        Select Case Me._FATypeIni

            Case CONSTANT.FIXED_ASSETS_TYPE._HOUSE
                x_po = New X_NhaCua(-1)
            Case CONSTANT.FIXED_ASSETS_TYPE._COMPUTER
                x_po = New X_MayTinh(-1)
            Case CONSTANT.FIXED_ASSETS_TYPE._PHOTO
                x_po = New X_MayPhoto(-1)
            Case CONSTANT.FIXED_ASSETS_TYPE._PROJECTOR
                x_po = New X_MayChieu(-1)
            Case CONSTANT.FIXED_ASSETS_TYPE._PRINTER
                x_po = New X_MayIn(-1)
            Case CONSTANT.FIXED_ASSETS_TYPE._OTO
                x_po = New X_Oto(-1)
            Case CONSTANT.FIXED_ASSETS_TYPE._INSTRUMENT
                x_po = New X_DungCu(-1)
            Case Else
                x_po = New X_NhaCua(-1)
        End Select

        Me.detailDA = New Query(x_po, Nothing).dataTable

        If (Me.detailDA Is Nothing) Then
            Me.grvDetail.DataSource = Me.detailDA
            Return False
        End If

        cm = Me.BindingContext(Me.detailDA)
        Me.grvDetail.DataSource = Me.detailDA

        Me.grvDetail.AutoGenerateColumns = True

        Dim i As Integer = 0
        For i = 0 To Me.grvDetail.ColumnCount - 1
            Me.grvDetail.Columns(i).HeaderText = x_po.getPoInfo.getPOInfoColumn(i).getColumnName.ToUpper
        Next
        Me.grvDetail.Columns(0).Visible = False

    End Function

    '' Tùy biến = Thêm tham số FAType
    Private Function loadHandover() As Boolean Implements SuperForm.loadHandover
        Me.grvHandover.ClearSelection()

        Dim x_handover As X_Handover = New X_Handover(-1)
        '' sqlWhere Tùy biến theo FAType
        Dim sqlWhere As String = "" & I_TSCD.ColumnName_FAType & " = " & Me._FATypeIni & ""
        Me.handoverDA = New Query(x_handover, sqlWhere).dataTable

        If (Me.handoverDA Is Nothing) Then
            Me.grvHandover.DataSource = Me.handoverDA
            Return False
        End If

        cm = Me.BindingContext(Me.handoverDA)
        Me.grvHandover.DataSource = Me.handoverDA
        Me.grvHandover.AutoGenerateColumns = True

        Dim i As Integer = 0
        For i = 0 To Me.grvHandover.ColumnCount - 1
            Me.grvHandover.Columns(i).HeaderText = x_handover.getPoInfo.getPOInfoColumn(i).getColumnName.ToUpper
        Next

        Me.grvHandover.Columns(x_handover.getPoInfo.getKey).Visible = False

    End Function

    '' Tùy biến = Thêm tham số FAType
    Private Function loadInventory() As Boolean Implements SuperForm.loadInventory
        Me.grvInventory.ClearSelection()

        Dim x_inventory As X_Inventory = New X_Inventory(-1)
        Dim sqlWhere As String = "" & I_TSCD.ColumnName_FAType & " = " & Me._FATypeIni & ""
        Me.inventoryDA = New Query(x_inventory, sqlWhere).dataTable
        If (Me.inventoryDA Is Nothing) Then
            Me.grvInventory.DataSource = Me.inventoryDA
            Return False
        End If
        cm = Me.BindingContext(Me.inventoryDA)
        Me.grvInventory.DataSource = Me.inventoryDA
        Me.grvInventory.AutoGenerateColumns = True

        Dim i As Integer = 0
        For i = 0 To Me.grvInventory.ColumnCount - 1
            Me.grvInventory.Columns(i).HeaderText = x_inventory.getPoInfo.getPOInfoColumn(i).getColumnName.ToUpper
        Next
        Me.grvInventory.Columns(x_inventory.getPoInfo.getKey).Visible = False

    End Function

    '' Tùy biến = Thêm tham số FAType
    Private Function loadRepair() As Boolean Implements SuperForm.loadRepair
        Me.grvRepair.ClearSelection()

        Dim x_repair As X_Repair = New X_Repair(-1)
        '' sqlWhere tùy biến theo FAType
        Dim sqlWhere As String = "" & I_TSCD.ColumnName_FAType & " = " & Me._FATypeIni & ""
        Me.repairDA = New Query(x_repair, sqlWhere).dataTable
        If (Me.repairDA Is Nothing) Then
            Me.grvRepair.DataSource = Me.repairDA
            Return False
        End If
        cm = Me.BindingContext(Me.repairDA)
        Me.grvRepair.DataSource = Me.repairDA
        Me.grvRepair.AutoGenerateColumns = True

        Dim i As Integer = 0
        For i = 0 To Me.grvRepair.ColumnCount - 1
            Me.grvRepair.Columns(i).HeaderText = x_repair.getPoInfo.getPOInfoColumn(i).getColumnName.ToUpper
        Next
        Me.grvRepair.Columns(x_repair.getPoInfo.getKey).Visible = False

    End Function

    '' Tùy biến = Thêm tham số FAType
    Private Function loadDisposal() As Boolean Implements SuperForm.loadDisposal
        Me.grvDisposal.ClearSelection()

        Dim x_disposal As X_Disposal = New X_Disposal(-1)
        '' sqlWhere tùy biến theo FAType
        Dim sqlWhere As String = "" & I_TSCD.ColumnName_FAType & " = " & Me._FATypeIni & ""
        Me.disposalDA = New Query(x_disposal, sqlWhere).dataTable
        If (Me.disposalDA Is Nothing) Then
            Me.grvDisposal.DataSource = Me.disposalDA
            Return False
        End If
        cm = Me.BindingContext(Me.disposalDA)
        Me.grvDisposal.DataSource = Me.disposalDA
        Me.grvDisposal.AutoGenerateColumns = True

        Dim i As Integer = 0
        For i = 0 To Me.grvDisposal.ColumnCount - 1
            Me.grvDisposal.Columns(i).HeaderText = x_disposal.getPoInfo.getPOInfoColumn(i).getColumnName.ToUpper
        Next
        Me.grvDisposal.Columns(x_disposal.getPoInfo.getKey).Visible = False

    End Function

    Private Sub grvFA_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvFA.RowHeaderMouseClick

        Me._curRowFASelected = e.RowIndex
        Me.grvFA.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvFA.Rows(e.RowIndex).Selected = True




        '' Xác đinh Detail tương ứng
        specifyCorrespondingDetail()

        '' Xác định Handover tương ứng
        specifyCorrespondingHandover()

        '' Xác định Inventory tương ứng
        specifyCorrespondingInventory()

        '' Xác định Repair tương ứng
        specifyCorrespondingRepair()

        '' Xác định Disposal tương ứng
        specifyCorrespondingDisposal()

    End Sub

    Private Sub grvFA_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvFA.CellMouseClick
        If (Me.faDA Is Nothing) Then
            Return
        End If
        '' Viet: Khởi tạo dòng đầu tiên được chọn
        If (e.RowIndex < 0 Or e.RowIndex > Me.faDA.Rows.Count - 1) Then
            Return
        End If
        Me._curRowFASelected = e.RowIndex
        Me.grvFA.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvFA.Rows(e.RowIndex).Selected = True
        specifyCorrespondingDetail()
        specifyCorrespondingDisposal()
        specifyCorrespondingHandover()
        specifyCorrespondingInventory()
        specifyCorrespondingRepair()
    End Sub

    Public Function specifyCorrespondingDetail() As Boolean Implements SuperForm.specifyCorrespondingDetail

        If (Me.detailDA Is Nothing Or Me.faDA Is Nothing) Then
            Return False
        End If

        If (Me._curRowFASelected < 0 Or Me._curRowFASelected > (Me.faDA.Rows.Count - 1)) Then
            Return False
        End If

        Dim parentID As Integer = Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id)

        '' Xác định Detail tương ứng
        Dim da As DataTable = New DataTable
        da = Me.detailDA.Clone
        Dim i As Integer = 0
        For i = 0 To Me.detailDA.Rows.Count - 1
            If (Me.detailDA.Rows(i)(0).Equals(parentID)) Then
                Dim daRow As DataRow = Me.detailDA.Rows(i)
                da.ImportRow(daRow)
                Me._curRowDetailSelected = i
                Exit For
            End If
        Next

        Me.grvDetail.DataSource = da
    End Function

    Public Function specifyCorrespondingHandover() As Boolean Implements SuperForm.specifyCorrespondingHandover
        If (Me.handoverDA Is Nothing Or Me.faDA Is Nothing) Then
            Return False
        End If

        If (Me._curRowFASelected < 0 Or Me._curRowFASelected > (Me.faDA.Rows.Count - 1)) Then
            Return False
        End If

        Dim parentID As Integer = Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id)
        Dim da As DataTable = Me.handoverDA.Clone

        Dim i As Integer = 0
        For i = 0 To Me.handoverDA.Rows.Count - 1
            If (Me.handoverDA.Rows(i)(I_Handover.ColumnName_parentID).Equals(parentID)) Then
                Dim dr As DataRow = Me.handoverDA.Rows(i)
                da.ImportRow(dr)
            End If
        Next

        Me.grvHandover.DataSource = da

    End Function

    Public Function specifyCorrespondingInventory() As Boolean Implements SuperForm.specifyCorrespondingInventory
        If (Me.inventoryDA Is Nothing Or Me.faDA Is Nothing) Then
            Return False
        End If

        If (Me._curRowFASelected < 0 Or Me._curRowFASelected > (Me.faDA.Rows.Count - 1)) Then
            Return False
        End If

        Dim parentID As Integer = Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id)
        Dim da As DataTable = Me.inventoryDA.Clone

        Dim i As Integer = 0
        For i = 0 To Me.inventoryDA.Rows.Count - 1
            If (Me.inventoryDA.Rows(i)(I_Inventory.ColumnName_parentID).Equals(parentID)) Then
                Dim dr As DataRow = Me.inventoryDA.Rows(i)
                da.ImportRow(dr)
            End If
        Next

        Me.grvInventory.DataSource = da
    End Function

    Public Function specifyCorrespondingRepair() As Boolean Implements SuperForm.specifyCorrespondingRepair
        If (Me.repairDA Is Nothing Or Me.faDA Is Nothing) Then
            Return False
        End If

        If (Me._curRowFASelected < 0 Or Me._curRowFASelected > (Me.faDA.Rows.Count - 1)) Then
            Return False
        End If

        Dim parentID As Integer = Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id)
        Dim da As DataTable = Me.repairDA.Clone

        Dim i As Integer = 0
        For i = 0 To Me.repairDA.Rows.Count - 1
            If (Me.repairDA.Rows(i)(I_Repair.ColumnName_parentID).Equals(parentID)) Then
                Dim dr As DataRow = Me.repairDA.Rows(i)
                da.ImportRow(dr)
            End If
        Next

        Me.grvRepair.DataSource = da
    End Function

    Public Function specifyCorrespondingDisposal() As Boolean Implements SuperForm.specifyCorrespondingDisposal
        If (Me.disposalDA Is Nothing Or Me.faDA Is Nothing) Then
            Return False
        End If

        If (Me._curRowFASelected < 0 Or Me._curRowFASelected > (Me.faDA.Rows.Count - 1)) Then
            Return False
        End If

        Dim parentID As Integer = Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id)
        Dim da As DataTable = Me.disposalDA.Clone

        Dim i As Integer = 0
        For i = 0 To Me.disposalDA.Rows.Count - 1
            If (Me.disposalDA.Rows(i)(I_Disposal.ColumnName_parentID).Equals(parentID)) Then
                Dim dr As DataRow = Me.disposalDA.Rows(i)
                da.ImportRow(dr)
            End If
        Next

        Me.grvDisposal.DataSource = da
    End Function

    '' Việt: Viết thêm cho các case: Xong
    Private Sub newFAMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newFAMni.Click
        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2
        Select Case Me._FATypeIni

            Case CONSTANT.FIXED_ASSETS_TYPE._HOUSE
                Dim frmHouse As FrmHouse
                frmHouse = New FrmHouse(New X_TSCD(-1), New X_NhaCua(-1), Me)
                frmHouse.StartPosition = FormStartPosition.Manual
                frmHouse.Location = New Point(xC - frmHouse.Width / 2, y)
                frmHouse.Visible = True
            Case CONSTANT.FIXED_ASSETS_TYPE._COMPUTER
                Dim frmComputer As FrmComputer
                frmComputer = New FrmComputer(New X_TSCD(-1), New X_MayTinh(-1), Me)
                frmComputer.StartPosition = FormStartPosition.Manual
                frmComputer.Location = New Point(xC - frmComputer.Width / 2, y)
                frmComputer.Visible = True
            Case CONSTANT.FIXED_ASSETS_TYPE._PHOTO
                Dim frmPhoto As FrmPhotocopier
                frmPhoto = New FrmPhotocopier(New X_TSCD(-1), New X_MayPhoto(-1), Me)
                frmPhoto.StartPosition = FormStartPosition.Manual
                frmPhoto.Location = New Point(xC - frmPhoto.Width / 2, y)
                frmPhoto.Visible = True
            Case CONSTANT.FIXED_ASSETS_TYPE._PROJECTOR
                Dim frmProjector As FrmProjectors
                frmProjector = New FrmProjectors(New X_TSCD(-1), New X_MayChieu(-1), Me)
                frmProjector.StartPosition = FormStartPosition.Manual
                frmProjector.Location = New Point(xC - frmProjector.Width / 2, y)
                frmProjector.Visible = True
            Case CONSTANT.FIXED_ASSETS_TYPE._PRINTER
                Dim frmPrinter As FrmPrinter
                frmPrinter = New FrmPrinter(New X_TSCD(-1), New X_MayIn(-1), Me)
                frmPrinter.StartPosition = FormStartPosition.Manual
                frmPrinter.Location = New Point(xC - frmPrinter.Width / 2, y)
                frmPrinter.Visible = True
            Case CONSTANT.FIXED_ASSETS_TYPE._OTO
                Dim frmOto As FrmOto
                frmOto = New FrmOto(New X_TSCD(-1), New X_Oto(-1), Me)
                frmOto.StartPosition = FormStartPosition.Manual
                frmOto.Location = New Point(xC - frmOto.Width / 2, y)
                frmOto.Visible = True
            Case CONSTANT.FIXED_ASSETS_TYPE._INSTRUMENT
                Dim frmInstrument As FrmInstrument
                frmInstrument = New FrmInstrument(New X_TSCD(-1), New X_DungCu(-1), Me)
                frmInstrument.StartPosition = FormStartPosition.Manual
                frmInstrument.Location = New Point(xC - frmInstrument.Width / 2, y)
                frmInstrument.Visible = True
            Case Else
                Dim frmHouse As FrmHouse
                frmHouse = New FrmHouse(New X_TSCD(-1), New X_NhaCua(-1), Me)
                frmHouse.StartPosition = FormStartPosition.Manual
                frmHouse.Location = New Point(xC - frmHouse.Width / 2, y)
                frmHouse.Visible = True
        End Select
    End Sub


    '' Việt: Viết thêm cho các case:Xong
    Private Sub formFAMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles formFAMni.Click
        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If


        Dim x_tscd As X_TSCD = New X_TSCD(-1)
        x_tscd.setValue(I_TSCD.ColumnName_id, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id))
        x_tscd.setValue(I_TSCD.ColumnName_MaSO, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_MaSO))
        x_tscd.setValue(I_TSCD.ColumnName_Ten, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_Ten))
        x_tscd.setValue(I_TSCD.ColumnName_DonViTrucThuoc, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_DonViTrucThuoc))
        x_tscd.setValue(I_TSCD.ColumnName_NguyenGia, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_NguyenGia))
        x_tscd.setValue(I_TSCD.ColumnName_TyLeHaoMon, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_TyLeHaoMon))
        x_tscd.setValue(I_TSCD.ColumnName_FAType, CONSTANT.FIXED_ASSETS_TYPE._HOUSE)
        x_tscd.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2

        Select Case Me._FATypeIni

            Case CONSTANT.FIXED_ASSETS_TYPE._HOUSE
                Dim x_nhacua As X_NhaCua = New X_NhaCua(-1)
                x_nhacua.setValue(I_NhaCua.ColumnName_id, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_id))
                x_nhacua.setValue(I_NhaCua.ColumnName_LoaiNha, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_LoaiNha))
                x_nhacua.setValue(I_NhaCua.ColumnName_DienTich, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_DienTich))
                x_nhacua.setValue(I_NhaCua.ColumnName_MucDichSuDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_MucDichSuDung))
                x_nhacua.setValue(I_NhaCua.ColumnName_NgayXayDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_NgayXayDung))
                x_nhacua.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

                Dim frmHouse As FrmHouse = New FrmHouse(x_tscd, x_nhacua, Me)
                frmHouse.StartPosition = FormStartPosition.Manual
                frmHouse.Location = New Point(xC - frmHouse.Width / 2, y)
                frmHouse.Visible = True
            Case CONSTANT.FIXED_ASSETS_TYPE._COMPUTER
                Dim x_maytinh As X_MayTinh = New X_MayTinh(-1)
                x_maytinh.setValue(I_MayTinh.ColumnName_id, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayTinh.ColumnName_id))
                x_maytinh.setValue(I_MayTinh.ColumnName_HangSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayTinh.ColumnName_HangSanXuat))
                x_maytinh.setValue(I_MayTinh.ColumnName_NamSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayTinh.ColumnName_NamSanXuat))
                x_maytinh.setValue(I_MayTinh.ColumnName_CauHinh, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayTinh.ColumnName_CauHinh))
                x_maytinh.setValue(I_MayTinh.ColumnName_MucDichSuDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayTinh.ColumnName_MucDichSuDung))
                x_maytinh.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

                Dim frmComputer As FrmComputer = New FrmComputer(x_tscd, x_maytinh, Me)
                frmComputer.StartPosition = FormStartPosition.Manual
                frmComputer.Location = New Point(xC - frmComputer.Width / 2, y)
                frmComputer.Visible = True

            Case CONSTANT.FIXED_ASSETS_TYPE._PHOTO
                Dim x_mayphoto As X_MayPhoto = New X_MayPhoto(-1)
                x_mayphoto.setValue(I_MayPhoto.ColumnName_id, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayPhoto.ColumnName_id))
                x_mayphoto.setValue(I_MayPhoto.ColumnName_HangSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayPhoto.ColumnName_HangSanXuat))
                x_mayphoto.setValue(I_MayPhoto.ColumnName_CongSuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayPhoto.ColumnName_CongSuat))
                x_mayphoto.setValue(I_MayPhoto.ColumnName_DinhLuongGiay, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayPhoto.ColumnName_DinhLuongGiay))
                x_mayphoto.setValue(I_MayPhoto.ColumnName_MucDichSuDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayPhoto.ColumnName_MucDichSuDung))
                x_mayphoto.setValue(I_MayPhoto.ColumnName_MucDichSuDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayPhoto.ColumnName_NamSanXuat))
                x_mayphoto.setValue(I_MayPhoto.ColumnName_TocDoChup, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayPhoto.ColumnName_TocDoChup))

                x_mayphoto.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

                Dim frmPhoto As FrmPhotocopier = New FrmPhotocopier(x_tscd, x_mayphoto, Me)
                frmPhoto.StartPosition = FormStartPosition.Manual
                frmPhoto.Location = New Point(xC - frmPhoto.Width / 2, y)
                frmPhoto.Visible = True

            Case CONSTANT.FIXED_ASSETS_TYPE._PROJECTOR
                Dim x_maychieu As X_MayChieu = New X_MayChieu(-1)
                x_maychieu.setValue(I_MayChieu.ColumnName_id, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_id))
                x_maychieu.setValue(I_MayChieu.ColumnName_BongDen, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_BongDen))
                x_maychieu.setValue(I_MayChieu.ColumnName_CongNghe, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_CongNghe))
                x_maychieu.setValue(I_MayChieu.ColumnName_CuongDoSang, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_CuongDoSang))
                x_maychieu.setValue(I_MayChieu.ColumnName_DoPhanGiai, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_DoPhanGiai))
                x_maychieu.setValue(I_MayChieu.ColumnName_DoTuongPhan, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_DoTuongPhan))
                x_maychieu.setValue(I_MayChieu.ColumnName_HangSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_HangSanXuat))
                x_maychieu.setValue(I_MayChieu.ColumnName_MucDichSuDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_MucDichSuDung))
                x_maychieu.setValue(I_MayChieu.ColumnName_NamSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_NamSanXuat))
                x_maychieu.setValue(I_MayChieu.ColumnName_TuoiTho, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayChieu.ColumnName_TuoiTho))

                x_maychieu.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

                Dim frmProjector As FrmProjectors = New FrmProjectors(x_tscd, x_maychieu, Me)
                frmProjector.StartPosition = FormStartPosition.Manual
                frmProjector.Location = New Point(xC - frmProjector.Width / 2, y)
                frmProjector.Visible = True

            Case CONSTANT.FIXED_ASSETS_TYPE._PRINTER
                Dim x_mayin As X_MayIn = New X_MayIn(-1)
                x_mayin.setValue(I_MayIn.ColumnName_id, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayIn.ColumnName_id))
                x_mayin.setValue(I_MayIn.ColumnName_CongSuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayIn.ColumnName_CongSuat))
                x_mayin.setValue(I_MayIn.ColumnName_DoPhanGiai, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayIn.ColumnName_DoPhanGiai))
                x_mayin.setValue(I_MayIn.ColumnName_HangSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayIn.ColumnName_HangSanXuat))
                x_mayin.setValue(I_MayIn.ColumnName_MucDichSuDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayIn.ColumnName_MucDichSuDung))
                x_mayin.setValue(I_MayIn.ColumnName_NamSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayIn.ColumnName_NamSanXuat))
                x_mayin.setValue(I_MayIn.ColumnName_TocDoIn, Me.detailDA.Rows(Me._curRowDetailSelected)(I_MayIn.ColumnName_TocDoIn))
                x_mayin.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

                Dim frmPrinter As FrmPrinter = New FrmPrinter(x_tscd, x_mayin, Me)
                frmPrinter.StartPosition = FormStartPosition.Manual
                frmPrinter.Location = New Point(xC - frmPrinter.Width / 2, y)
                frmPrinter.Visible = True

            Case CONSTANT.FIXED_ASSETS_TYPE._OTO
                Dim x_oto As X_Oto = New X_Oto(-1)
                x_oto.setValue(I_Oto.ColumnName_id, Me.detailDA.Rows(Me._curRowDetailSelected)(I_Oto.ColumnName_id))
                x_oto.setValue(I_Oto.ColumnName_BienKiemSoat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_Oto.ColumnName_BienKiemSoat))
                x_oto.setValue(I_Oto.ColumnName_HangSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_Oto.ColumnName_HangSanXuat))
                x_oto.setValue(I_Oto.ColumnName_MucDichSuDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_Oto.ColumnName_MucDichSuDung))
                x_oto.setValue(I_Oto.ColumnName_NamSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_Oto.ColumnName_NamSanXuat))

                x_oto.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

                Dim frmOto As FrmOto = New FrmOto(x_tscd, x_oto, Me)
                frmOto.StartPosition = FormStartPosition.Manual
                frmOto.Location = New Point(xC - frmOto.Width / 2, y)
                frmOto.Visible = True

            Case CONSTANT.FIXED_ASSETS_TYPE._INSTRUMENT
                Dim x_dungcu As X_DungCu = New X_DungCu(-1)
                x_dungcu.setValue(I_DungCu.ColumnName_id, Me.detailDA.Rows(Me._curRowDetailSelected)(I_DungCu.ColumnName_id))
                x_dungcu.setValue(I_DungCu.ColumnName_HangSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_DungCu.ColumnName_HangSanXuat))
                x_dungcu.setValue(I_DungCu.ColumnName_MucDichSuDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_DungCu.ColumnName_MucDichSuDung))
                x_dungcu.setValue(I_DungCu.ColumnName_NamSanXuat, Me.detailDA.Rows(Me._curRowDetailSelected)(I_DungCu.ColumnName_NamSanXuat))
                x_dungcu.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

                Dim frmInstrument As FrmInstrument = New FrmInstrument(x_tscd, x_dungcu, Me)
                frmInstrument.StartPosition = FormStartPosition.Manual
                frmInstrument.Location = New Point(xC - frmInstrument.Width / 2, y)
                frmInstrument.Visible = True

            Case Else
                Dim x_nhacua As X_NhaCua = New X_NhaCua(-1)
                x_nhacua.setValue(I_NhaCua.ColumnName_id, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_id))
                x_nhacua.setValue(I_NhaCua.ColumnName_LoaiNha, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_LoaiNha))
                x_nhacua.setValue(I_NhaCua.ColumnName_DienTich, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_DienTich))
                x_nhacua.setValue(I_NhaCua.ColumnName_MucDichSuDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_MucDichSuDung))
                x_nhacua.setValue(I_NhaCua.ColumnName_NgayXayDung, Me.detailDA.Rows(Me._curRowDetailSelected)(I_NhaCua.ColumnName_NgayXayDung))
                x_nhacua.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

                Dim frmHouse As FrmHouse = New FrmHouse(x_tscd, x_nhacua, Me)
                frmHouse.StartPosition = FormStartPosition.Manual
                frmHouse.Location = New Point(xC - frmHouse.Width / 2, y)
                frmHouse.Visible = True
        End Select
    End Sub

    Private Sub delFAMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles delFAMni.Click
        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If

        Dim x_tscd As X_TSCD = New X_TSCD(-1)
        x_tscd.setValue(I_TSCD.ColumnName_id, faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id))
        x_tscd.delete()

        Me.loadFA()
        Me.specifyCorrespondingDetail()

    End Sub

    Private Sub newHandoverMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newHandoverMni.Click

        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If

        Dim x_tscd As X_TSCD = New X_TSCD(-1)
        x_tscd.setValue(I_TSCD.ColumnName_id, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id))
        x_tscd.setValue(I_TSCD.ColumnName_MaSO, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_MaSO))
        x_tscd.setValue(I_TSCD.ColumnName_FAType, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_FAType))
        x_tscd.setValue(I_TSCD.ColumnName_IsBusy, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_IsBusy))

        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2

        Dim frmHandover As FrmHandover
        frmHandover = New FrmHandover(New X_Handover(-1), x_tscd, Me)
        frmHandover.StartPosition = FormStartPosition.Manual
        frmHandover.Location = New Point(xC - frmHandover.Width / 2, y)
        frmHandover.Visible = True
    End Sub

    Private Sub grvHandover_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvHandover.CellMouseClick
        If (e.RowIndex < 0 Or e.RowIndex > Me.handoverDA.Rows.Count - 1) Then
            Return
        End If

        If (Me.handoverDA Is Nothing) Then
            Return
        End If

        Dim i As Integer = 0
        For i = 0 To Me.handoverDA.Rows.Count - 1
            Dim da As DataTable = grvHandover.DataSource
            If (Me.handoverDA.Rows(i)(I_Handover.ColumnName_id).Equals(da.Rows(e.RowIndex)(I_Handover.ColumnName_id))) Then
                Me._curRowHandoverSelected = i
                Exit For
            End If
        Next

        Me.grvHandover.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvHandover.Rows(e.RowIndex).Selected = True
    End Sub

    Private Sub grvHandover_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvHandover.RowHeaderMouseClick

        If (Me.handoverDA Is Nothing) Then
            Return
        End If

        Dim i As Integer = 0
        For i = 0 To Me.handoverDA.Rows.Count - 1
            Dim da As DataTable = grvHandover.DataSource
            If (Me.handoverDA.Rows(i)(I_Handover.ColumnName_id).Equals(da.Rows(e.RowIndex)(I_Handover.ColumnName_id))) Then
                Me._curRowHandoverSelected = i
                Exit For
            End If
        Next
        Me.grvHandover.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvHandover.Rows(e.RowIndex).Selected = True
    End Sub

    Private Sub formHandoverMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles formHandoverMni.Click

        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If

        If (Me._curRowHandoverSelected < 0 Or (Me.handoverDA.Rows.Count - 1) < Me._curRowHandoverSelected) Then
            Return
        End If

        Dim x_handover As X_Handover = New X_Handover(-1)
        x_handover.setValue(I_Handover.ColumnName_id, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_id))
        x_handover.setValue(I_Handover.ColumnName_MaTS, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_MaTS))
        x_handover.setValue(I_Handover.ColumnName_NguoiGiao, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_NguoiGiao))
        x_handover.setValue(I_Handover.ColumnName_NguoiNhan, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_NguoiNhan))
        x_handover.setValue(I_Handover.ColumnName_ThoiGian, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_ThoiGian))
        x_handover.setValue(I_Handover.ColumnName_DiaDiem, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_DiaDiem))
        x_handover.setValue(I_Handover.ColumnName_FAType, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_FAType))
        x_handover.setValue(I_Handover.ColumnName_Status, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_Status))
        x_handover.setValue(I_Handover.ColumnName_parentID, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_parentID))
        x_handover.setValue(I_Handover.ColumnName_LoaiBanGiao, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_LoaiBanGiao))
        x_handover.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2

        Dim frmHandover As FrmHandover = New FrmHandover(x_handover, Nothing, Me)
        frmHandover.StartPosition = FormStartPosition.Manual
        frmHandover.Location = New Point(xC - frmHandover.Width / 2, y)
        frmHandover.Visible = True

    End Sub

    Private Sub delHandoverMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles delHandoverMni.Click
        If (Me.handoverDA Is Nothing) Then
            Return
        End If

        If (Me._curRowHandoverSelected < 0 Or (Me.handoverDA.Rows.Count - 1) < Me._curRowHandoverSelected) Then
            Return
        End If

        Dim x_handover As X_Handover = New X_Handover(-1)
        x_handover.setValue(I_Handover.ColumnName_id, Me.handoverDA.Rows(Me._curRowHandoverSelected)(I_Handover.ColumnName_id))
        x_handover.delete()

        loadHandover()
        specifyCorrespondingHandover()

    End Sub

    Private Sub newInventoryMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newInventoryMni.Click
        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If

        Dim x_tscd As X_TSCD = New X_TSCD(-1)
        x_tscd.setValue(I_TSCD.ColumnName_id, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id))
        x_tscd.setValue(I_TSCD.ColumnName_MaSO, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_MaSO))
        x_tscd.setValue(I_TSCD.ColumnName_FAType, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_FAType))

        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2

        Dim frmInventory As FrmInventory
        frmInventory = New FrmInventory(New X_Inventory(-1), x_tscd, Me)
        frmInventory.StartPosition = FormStartPosition.Manual
        frmInventory.Location = New Point(xC - frmInventory.Width / 2, y)
        frmInventory.Visible = True
    End Sub

    Private Sub grvInventory_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvInventory.CellMouseClick
        If (e.RowIndex < 0 Or e.RowIndex > Me.inventoryDA.Rows.Count - 1) Then
            Return
        End If

        If (Me.inventoryDA Is Nothing) Then
            Return
        End If

        Dim i As Integer = 0
        For i = 0 To Me.inventoryDA.Rows.Count - 1
            Dim da As DataTable = grvInventory.DataSource
            If (Me.inventoryDA.Rows(i)(I_Inventory.ColumnName_id).Equals(da.Rows(e.RowIndex)(I_Inventory.ColumnName_id))) Then
                Me._curRowInventorySelected = i
                Exit For
            End If
        Next

        Me.grvInventory.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvInventory.Rows(e.RowIndex).Selected = True
    End Sub


    Private Sub grvInventory_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvInventory.RowHeaderMouseClick
        If (Me.inventoryDA Is Nothing) Then
            Return
        End If

        Dim i As Integer = 0
        For i = 0 To Me.inventoryDA.Rows.Count - 1
            Dim da As DataTable = grvInventory.DataSource
            If (Me.inventoryDA.Rows(i)(I_Inventory.ColumnName_id).Equals(da.Rows(e.RowIndex)(I_Inventory.ColumnName_id))) Then
                Me._curRowInventorySelected = i
                Exit For
            End If
        Next

        Me.grvInventory.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvInventory.Rows(e.RowIndex).Selected = True
    End Sub

    Private Sub formInventoryMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles formInventoryMni.Click
        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If

        If (Me._curRowInventorySelected < 0 Or (Me.inventoryDA.Rows.Count - 1) < Me._curRowInventorySelected) Then
            Return
        End If


        Dim x_inventory As X_Inventory = New X_Inventory(-1)
        x_inventory.setValue(I_Inventory.ColumnName_id, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_id))
        x_inventory.setValue(I_Inventory.ColumnName_MaTS, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_MaTS))
        x_inventory.setValue(I_Inventory.ColumnName_NguyenGia, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_NguyenGia))
        x_inventory.setValue(I_Inventory.ColumnName_GiaTriHaoMon, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_GiaTriHaoMon))
        x_inventory.setValue(I_Inventory.ColumnName_GiaTriConLai, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_GiaTriConLai))
        x_inventory.setValue(I_Inventory.ColumnName_TinhTrangKiThuat, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_TinhTrangKiThuat))
        x_inventory.setValue(I_Inventory.ColumnName_ThoiGian, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_ThoiGian))
        x_inventory.setValue(I_Inventory.ColumnName_DiaDiem, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_DiaDiem))
        x_inventory.setValue(I_Inventory.ColumnName_HDKiemKe, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_HDKiemKe))
        x_inventory.setValue(I_Inventory.ColumnName_FAType, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_FAType))
        x_inventory.setValue(I_Inventory.ColumnName_Status, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_Status))
        x_inventory.setValue(I_Inventory.ColumnName_parentID, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_parentID))
        x_inventory.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2

        Dim frmInventory As FrmInventory = New FrmInventory(x_inventory, Nothing, Me)
        frmInventory.StartPosition = FormStartPosition.Manual
        frmInventory.Location = New Point(xC - frmInventory.Width / 2, y)
        frmInventory.Visible = True

    End Sub


    Private Sub delInventoryMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles delInventoryMni.Click
        If (Me.inventoryDA Is Nothing) Then
            Return
        End If

        If (Me._curRowInventorySelected < 0 Or (Me.inventoryDA.Rows.Count - 1) < Me._curRowInventorySelected) Then
            Return
        End If

        Dim x_inventory As X_Inventory = New X_Inventory(-1)
        x_inventory.setValue(I_Inventory.ColumnName_id, Me.inventoryDA.Rows(Me._curRowInventorySelected)(I_Inventory.ColumnName_id))
        x_inventory.delete()

        loadInventory()
        specifyCorrespondingInventory()
    End Sub

    Private Sub newRepairMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newRepairMni.Click
        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If

        Dim x_tscd As X_TSCD = New X_TSCD(-1)
        x_tscd.setValue(I_TSCD.ColumnName_id, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id))
        x_tscd.setValue(I_TSCD.ColumnName_MaSO, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_MaSO))
        x_tscd.setValue(I_TSCD.ColumnName_FAType, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_FAType))

        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2

        Dim frmRepair As FrmRepair
        frmRepair = New FrmRepair(New X_Repair(-1), x_tscd, Me)
        frmRepair.StartPosition = FormStartPosition.Manual
        frmRepair.Location = New Point(xC - frmRepair.Width / 2, y)
        frmRepair.Visible = True
    End Sub

    Private Sub grvRepair_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvRepair.CellMouseClick
        If (e.RowIndex < 0 Or e.RowIndex > Me.repairDA.Rows.Count - 1) Then
            Return
        End If

        Dim i As Integer = 0
        For i = 0 To Me.repairDA.Rows.Count - 1
            Dim da As DataTable = Me.grvRepair.DataSource
            If (Me.repairDA.Rows(i)(I_Repair.ColumnName_id).Equals(da.Rows(e.RowIndex)(I_Repair.ColumnName_id))) Then
                Me._curRowRepairSelected = i
                Exit For
            End If
        Next

        Me.grvRepair.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvRepair.Rows(e.RowIndex).Selected = True
    End Sub

    '' Sự kiện click chuột vào Row
    Private Sub grvRepair_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvRepair.RowHeaderMouseClick
        If (Me.repairDA Is Nothing) Then
            Return
        End If

        Dim i As Integer = 0
        For i = 0 To Me.repairDA.Rows.Count - 1
            Dim da As DataTable = Me.grvRepair.DataSource
            If (Me.repairDA.Rows(i)(I_Repair.ColumnName_id).Equals(da.Rows(e.RowIndex)(I_Repair.ColumnName_id))) Then
                Me._curRowRepairSelected = i
                Exit For
            End If
        Next

        Me.grvRepair.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvRepair.Rows(e.RowIndex).Selected = True
    End Sub

    Private Sub formRepairMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles formRepairMni.Click
        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If

        If (Me._curRowRepairSelected < 0 Or (Me.repairDA.Rows.Count - 1) < Me._curRowRepairSelected) Then
            Return
        End If


        Dim x_repair As X_Repair = New X_Repair(-1)
        x_repair.setValue(I_Repair.ColumnName_id, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_id))
        x_repair.setValue(I_Repair.ColumnName_MaTS, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_MaTS))
        x_repair.setValue(I_Repair.ColumnName_DaiDienDVSuaChua, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_DaiDienDVSuaChua))
        x_repair.setValue(I_Repair.ColumnName_DaiDienDVTS, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_DaiDienDVTS))
        x_repair.setValue(I_Repair.ColumnName_ThoiGian, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_ThoiGian))
        x_repair.setValue(I_Repair.ColumnName_BPSuaChua, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_BPSuaChua))
        x_repair.setValue(I_Repair.ColumnName_NDSuaChua, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_NDSuaChua))
        x_repair.setValue(I_Repair.ColumnName_GiaDuToan, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_GiaDuToan))
        x_repair.setValue(I_Repair.ColumnName_ChiPhiThucTe, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_ChiPhiThucTe))
        x_repair.setValue(I_Repair.ColumnName_KQKiemTra, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_KQKiemTra))
        x_repair.setValue(I_Repair.ColumnName_FAType, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_FAType))
        x_repair.setValue(I_Repair.ColumnName_Status, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_Status))
        x_repair.setValue(I_Repair.ColumnName_parentID, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_parentID))
        x_repair.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2

        Dim frmRepair As FrmRepair = New FrmRepair(x_repair, Nothing, Me)
        frmRepair.StartPosition = FormStartPosition.Manual
        frmRepair.Location = New Point(xC - frmRepair.Width / 2, y)
        frmRepair.Visible = True

    End Sub

    Private Sub delRepairMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles delRepairMni.Click
        If (Me.repairDA Is Nothing) Then
            Return
        End If

        If (Me._curRowRepairSelected < 0 Or (Me.repairDA.Rows.Count - 1) < Me._curRowRepairSelected) Then
            Return
        End If

        Dim x_repair As X_Repair = New X_Repair(-1)
        x_repair.setValue(I_Repair.ColumnName_id, Me.repairDA.Rows(Me._curRowRepairSelected)(I_Repair.ColumnName_id))
        x_repair.delete()

        loadRepair()
        specifyCorrespondingRepair()

    End Sub


    Private Sub newDisposalMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newDisposalMni.Click
        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If

        Dim x_tscd As X_TSCD = New X_TSCD(-1)
        x_tscd.setValue(I_TSCD.ColumnName_id, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_id))
        x_tscd.setValue(I_TSCD.ColumnName_MaSO, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_MaSO))
        x_tscd.setValue(I_TSCD.ColumnName_FAType, Me.faDA.Rows(Me._curRowFASelected)(I_TSCD.ColumnName_FAType))

        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2

        Dim frmDisposal As FrmDisposal
        frmDisposal = New FrmDisposal(New X_Disposal(-1), x_tscd, Me)
        frmDisposal.StartPosition = FormStartPosition.Manual
        frmDisposal.Location = New Point(xC - frmDisposal.Width / 2, y)
        frmDisposal.Visible = True

    End Sub

    Private Sub grvDisposal_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvDisposal.CellMouseClick
        If (e.RowIndex < 0 Or e.RowIndex > Me.disposalDA.Rows.Count - 1) Then
            Return
        End If

        If (Me.disposalDA Is Nothing) Then
            Return
        End If

        Dim i As Integer = 0
        For i = 0 To Me.disposalDA.Rows.Count - 1
            Dim da As DataTable = grvDisposal.DataSource
            If (Me.disposalDA.Rows(i)(I_Disposal.ColumnName_id).Equals(da.Rows(e.RowIndex)(I_Disposal.ColumnName_id))) Then
                Me._curRowDisposalSelected = i
                Exit For
            End If
        Next

        Me.grvDisposal.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvDisposal.Rows(e.RowIndex).Selected = True
    End Sub


    '' Sự kiện click chuột vào Row
    Private Sub grvDisposal_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles grvDisposal.RowHeaderMouseClick
        If (Me.disposalDA Is Nothing) Then
            Return
        End If

        Dim i As Integer = 0
        For i = 0 To Me.disposalDA.Rows.Count - 1
            Dim da As DataTable = grvDisposal.DataSource
            If (Me.disposalDA.Rows(i)(I_Disposal.ColumnName_id).Equals(da.Rows(e.RowIndex)(I_Disposal.ColumnName_id))) Then
                Me._curRowDisposalSelected = i
                Exit For
            End If
        Next

        Me.grvDisposal.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect
        Me.grvDisposal.Rows(e.RowIndex).Selected = True
    End Sub

    Private Sub formDisposalMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles formDisposalMni.Click
        If (Me.faDA Is Nothing) Then
            Return
        End If

        If (Me._curRowFASelected < 0 Or (Me.faDA.Rows.Count - 1) < Me._curRowFASelected) Then
            Return
        End If

        If (Me._curRowDisposalSelected < 0 Or (Me.disposalDA.Rows.Count - 1) < Me._curRowDisposalSelected) Then
            Return
        End If


        Dim x_disposal As X_Disposal = New X_Disposal(-1)
        x_disposal.setValue(I_Disposal.ColumnName_id, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_id))
        x_disposal.setValue(I_Disposal.ColumnName_MaTS, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_MaTS))
        x_disposal.setValue(I_Disposal.ColumnName_HDThanhLy, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_HDThanhLy))
        x_disposal.setValue(I_Disposal.ColumnName_NguyenGia, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_NguyenGia))
        x_disposal.setValue(I_Disposal.ColumnName_SoHaoMon, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_SoHaoMon))
        x_disposal.setValue(I_Disposal.ColumnName_GiaTriConLai, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_GiaTriConLai))
        x_disposal.setValue(I_Disposal.ColumnName_ChiPhiTL, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_ChiPhiTL))
        x_disposal.setValue(I_Disposal.ColumnName_NoiDungTL, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_NoiDungTL))
        x_disposal.setValue(I_Disposal.ColumnName_ThoiGian, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_ThoiGian))
        x_disposal.setValue(I_Disposal.ColumnName_DiaDiem, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_DiaDiem))
        x_disposal.setValue(I_Disposal.ColumnName_FAType, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_FAType))
        x_disposal.setValue(I_Disposal.ColumnName_Status, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_Status))
        x_disposal.setValue(I_Disposal.ColumnName_parentID, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_parentID))
        x_disposal.setBehave(CONSTANT.BEHAVE_TYPE._UPDATE)

        Dim x = Me.Location.X
        Dim y = Me.Location.Y + 86
        Dim width = Me.Width
        Dim xC = (x + width) / 2

        Dim frmDisposal As FrmDisposal = New FrmDisposal(x_disposal, Nothing, Me)
        frmDisposal.StartPosition = FormStartPosition.Manual
        frmDisposal.Location = New Point(xC - frmDisposal.Width / 2, y)
        frmDisposal.Visible = True

    End Sub


    Private Sub delDisposalMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles delDisposalMni.Click
        If (Me.disposalDA Is Nothing) Then
            Return
        End If

        If (Me._curRowDisposalSelected < 0 Or (Me.disposalDA.Rows.Count - 1) < Me._curRowDisposalSelected) Then
            Return
        End If

        Dim x_disposal As X_Disposal = New X_Disposal(-1)
        x_disposal.setValue(I_Disposal.ColumnName_id, Me.disposalDA.Rows(Me._curRowDisposalSelected)(I_Disposal.ColumnName_id))
        x_disposal.delete()

        loadDisposal()
        specifyCorrespondingDisposal()

    End Sub

    Private Sub searchFAMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchFAMni.Click
        Dim searchBox As SearchBox = New SearchBox(Me.grvFA, I_TSCD.TableName)
        searchBox.Visible = True
    End Sub


    Private Sub searchHandoverMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchHandoverMni.Click
        Dim searchBox As SearchBox = New SearchBox(Me.grvHandover, I_TSCD.TableName)
        searchBox.Visible = True
    End Sub


    Private Sub searchInventoryMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchInventoryMni.Click
        Dim searchBox As SearchBox = New SearchBox(Me.grvInventory, I_TSCD.TableName)
        searchBox.Visible = True
    End Sub

    Private Sub searchRepairMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchRepairMni.Click
        Dim searchBox As SearchBox = New SearchBox(Me.grvRepair, I_TSCD.TableName)
        searchBox.Visible = True
    End Sub


    Private Sub searchDisposalMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchDisposalMni.Click
        Dim searchBox As SearchBox = New SearchBox(Me.grvDisposal, I_TSCD.TableName)
        searchBox.Visible = True
    End Sub


    Private Sub excelFAMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles excelFAMni.Click
        MyLibrary.toExcell(Me.grvFA)
    End Sub


    Private Sub excelHandoverMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles excelHandoverMni.Click
        MyLibrary.toExcell(Me.grvHandover)
    End Sub

    Private Sub excelInventoryMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles excelInventoryMni.Click
        MyLibrary.toExcell(Me.grvInventory)
    End Sub

    Private Sub excelRepairMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles excelRepairMni.Click
        MyLibrary.toExcell(Me.grvRepair)
    End Sub


    Private Sub excelDisposalMni_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles excelDisposalMni.Click
        MyLibrary.toExcell(Me.grvDisposal)
    End Sub


    Private Sub menuTreeView_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles menuTreeView.AfterSelect
        ' iterate through parent nodes in the collection
        For Each node As TreeNode In Me.menuTreeView.Nodes
            CheckForChildern(node)
        Next node
    End Sub

    Private Sub CheckForChildern(ByVal node As TreeNode)
        ' check whether each parent node has child nodes
        If node.Nodes.Count > 0 Then
            ' iterate through child nodes in the collection
            For Each childnode As TreeNode In node.Nodes
                If childnode.IsSelected Then
                    Select Case childnode.Name
                        Case "childComputer"
                            Me._FATypeIni = CONSTANT.FIXED_ASSETS_TYPE._COMPUTER
                            Me.ini()
                            Me.loadAll()
                        Case "childProjector"
                            Me._FATypeIni = CONSTANT.FIXED_ASSETS_TYPE._PROJECTOR
                            Me.ini()
                            Me.loadAll()
                        Case "childPrinter"
                            Me._FATypeIni = CONSTANT.FIXED_ASSETS_TYPE._PRINTER
                            Me.ini()
                            Me.loadAll()
                        Case "childPhoto"
                            Me._FATypeIni = CONSTANT.FIXED_ASSETS_TYPE._PHOTO
                            Me.ini()
                            Me.loadAll()
                        Case "childHouse"
                            Me._FATypeIni = CONSTANT.FIXED_ASSETS_TYPE._HOUSE
                            Me.ini()
                            Me.loadAll()
                        Case "childOto"
                            Me._FATypeIni = CONSTANT.FIXED_ASSETS_TYPE._OTO
                            Me.ini()
                            Me.loadAll()
                        Case "childInstrument"
                            Me._FATypeIni = CONSTANT.FIXED_ASSETS_TYPE._INSTRUMENT
                            Me.ini()
                            Me.loadAll()
                        Case "childCouncilInventory"
                            Dim councilManagement As New CouncilManagement
                            councilManagement.Visible = True
                        Case "childCouncilDisposal"
                            Dim councilManagement As New CouncilManagement
                            councilManagement.Visible = True
                    End Select
                End If
                ' Do recursive call
                CheckForChildern(childnode)
            Next childnode

        End If

    End Sub

    Private Function loadCouncil() As Boolean Implements SuperForm.loadCouncil

    End Function

    Private Sub grvHandover_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grvHandover.CellContentClick

    End Sub
End Class